﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using QualityRpt.Service;
using QualityRpt.Utils;

namespace QualityRPT
{
    public partial class addjob : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this.text_jobName.Value = "任务" + DateTime.Now.ToString("yyyyMMdd");
            }
            else
            {
                string strJobStartTime = Request.Params["text_jobStartTime"];
                DateTime jobStarTime = DateTime.Now;
                if (strJobStartTime != null && strJobStartTime.Trim() != string.Empty)
                {
                    jobStarTime = DateTime.Parse(strJobStartTime);
                }
                string strDataStartTime = Request.Params["text_dataStartTime"];
                DateTime dataStartTime = DateTime.Now.AddDays(-7);
                if (strDataStartTime != null && strDataStartTime.Trim() != string.Empty)
                {
                    dataStartTime = DateTime.Parse(strDataStartTime);
                }
                string strDataEndTime = Request.Params["text_dataEndTime"];
                DateTime dataEndTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                if (strDataEndTime != null && strDataEndTime.Trim() != string.Empty)
                {
                    dataEndTime = DateTime.Parse(strDataEndTime);
                }
                DataRow jobRow = ServiceInfoService.GetSchema().NewRow();
                jobRow["JOB_NAME"] = text_jobName.Value;
                jobRow["JOB_TYPE"] = Request.Params["sel_job_type"];
                jobRow["JOB_START_TIME"] = jobStarTime;
                jobRow["DATA_START_TIME"] = dataStartTime;
                jobRow["DATA_END_TIME"] = dataEndTime;
                jobRow["CREATE_TIME"] = DateTime.Now;
                jobRow["DATA_STATUS"] = 0;
				jobRow["USER_ID"] = AppUtils.GetUserId(Session);
                try
                {
                    ServiceInfoService.Save(jobRow);
                    Response.Redirect("joblist.aspx?pid="+Request.Params["pid"]+"&cid="+Request.Params["cid"]+"&t="+DateTime.Now.Ticks);
                }
                catch (Exception ex)
                {
                    Response.Write("<script type='text/javascript'>alert('出现异常"+ex.ToString()+"');</script>");
                }
            }
        }
    }
}